<script setup>
import { ref } from 'vue'
import { editAccountService } from '@/api/account'
const dialogVisible = ref(false)
const roleRadio = ref()
const userId = ref()
const onSubmit = async () => {
  await editAccountService(userId.value, roleRadio.value)
  ElMessage({ type: 'success', message: '修改成功' })
  emit('success')
  dialogVisible.value = false
}
const open = async ({ roleId, id }) => {
  dialogVisible.value = true
  roleRadio.value = roleId.toString()
  userId.value = id
}

const emit = defineEmits(['success'])

defineExpose({
  open
})
</script>
<template>
  <el-dialog v-model="dialogVisible" title="账号权限" width="30%">
    <div style="margin-top: 20px; text-align: center">
      <el-radio-group v-model="roleRadio">
        <el-radio size="large" label="1">管理员</el-radio>
        <el-radio size="large" label="2">普通用户</el-radio>
        <el-radio size="large" label="3">专家</el-radio>
      </el-radio-group>
    </div>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="onSubmit"> 确认 </el-button>
      </span>
    </template>
  </el-dialog>
</template>
